import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
const CryptoJS = require("crypto-js");
const publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyUUmpjvMiiU8mL3gvqXq\n' +
  'cTPylF6aYNL+FfiBaz6byOBuNp4/2A6MNqzMadrmsCw3PJaR7jQIq3OGltZYtyPI\n' +
  'QOpSgSv5/EuhDDQzIFM8IB3d67i2hYUHn2lwrpEvtvchdY+dGmkqnW1rE8JF1YhZ\n' +
  '+TNw7LtbTfkH+dUx5cHXxoC+sA6RmXnwjtPmluxUnnMK21l/lybHtPpMAipJok7V\n' +
  'p8ZgebOnb+fymDsZ/SeBg0iKgFLB/fITISxwn9HG1h1Jzn2AbLuhWd1sfnSYoBPj\n' +
  '2ECiVVeKEdP29HuhNuD8Zo9u25NSvJlg1i5ypYmN+SjDk/2bkl+KszUvZzqEbZh1\n' +
  'FwIDAQAB'

const privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJRSamO8yKJTyY\n' +
  'veC+pepxM/KUXppg0v4V+IFrPpvI4G42nj/YDow2rMxp2uawLDc8lpHuNAirc4aW\n' +
  '1li3I8hA6lKBK/n8S6EMNDMgUzwgHd3ruLaFhQefaXCukS+29yF1j50aaSqdbWsT\n' +
  'wkXViFn5M3Dsu1tN+Qf51THlwdfGgL6wDpGZefCO0+aW7FSecwrbWX+XJse0+kwC\n' +
  'KkmiTtWnxmB5s6dv5/KYOxn9J4GDSIqAUsH98hMhLHCf0cbWHUnOfYBsu6FZ3Wx+\n' +
  'dJigE+PYQKJVV4oR0/b0e6E24Pxmj27bk1K8mWDWLnKliY35KMOT/ZuSX4qzNS9n\n' +
  'OoRtmHUXAgMBAAECggEATC8/tPa3sqbrrAlbk+6rslPug5jXqMTU5q4dFuIpB71k\n' +
  'GoqGMhs3mc6IxZzVa2QhOG7qKBdMHNHq5ReXlyMVPvUza6+gvY5HFJ6Bp7+555JG\n' +
  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1Fo7TGEpvpIBL9XxwQoE/x4XD5WLLzQpV/YN/5xEaR1jxjKcC8R3u7oIWN3Xlk\n' +
  'GVQHlEwtUCO1Cs+Hj11ztWNInXxDabwIUiZ6WaD7a01wfjhsG2BHVrCzBIuEnqft\n' +
  'YN5aVbqopvHdF8pAble4Awpr\n'


const aesPrivateKey = 'uUS#N6okHJqsh0BB'
// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}


// aes加密
export function aesEncrypt(txt) {
  // const encryptor = new JSEncrypt()
  // encryptor.setPublicKey(publicKey) // 设置公钥
  // return encryptor.encrypt(txt) // 对数据进行加密

  const key = CryptoJS.enc.Utf8.parse(aesPrivateKey);
  const iv = CryptoJS.lib.WordArray.create(CryptoJS.enc.Utf8.parse(aesPrivateKey));
  const encrypted = CryptoJS.AES.encrypt(txt, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

// aes解密
export function aesDecrypt(txt) {
  const key = CryptoJS.enc.Utf8.parse(aesPrivateKey);
  const iv = CryptoJS.lib.WordArray.create(CryptoJS.enc.Utf8.parse(aesPrivateKey));
  const bytes = CryptoJS.AES.decrypt(txt, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  const originalText = bytes.toString(CryptoJS.enc.Utf8);
  return originalText;
}


